[XEND] Save device updates to VM configuration via Xen API
authorAlastair Tse <atse@xensource.com>
Fri, 6 Oct 2006 16:34:49 +0000 (17:34 +0100)
committerAlastair Tse <atse@xensource.com>
Fri, 6 Oct 2006 16:34:49 +0000 (17:34 +0100)
Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index a33345e2950381e6086b4ba44465707463d79a71..dc9595f94ea69c80f314fc85c13ea3ae7aa91855 100644 (file)
@@ -963,6 +963,7 @@ class XendAPI:
             dom = xendom.get_vm_by_uuid(vbd_struct['VM'])
             try:
                 vbd_ref = dom.create_vbd(vbd_struct)
+                xendom.managed_config_save(dom)
                 return xen_api_success(vbd_ref)
             except XendError:
                 return xen_api_error(XEND_ERROR_TODO)
@@ -1029,6 +1030,7 @@ class XendAPI:
             dom = xendom.get_vm_by_uuid(vif_struct['VM'])
             try:
                 vif_ref = dom.create_vif(vif_struct)
+                xendom.managed_config_save(dom)                
                 return xen_api_success(vif_ref)
             except XendError:
                 return xen_api_error(XEND_ERROR_TODO)
index dee31a331b2174f87a92be46423f75d0b1624cf9..361c7613c56f53213ad2bcba50294f32cdf169e8 100644 (file)
@@ -143,7 +143,7 @@ class XendDomain:
             running = self._running_domains()
             managed = self._managed_domains()
 
-            # add all active domains, replacing managed ones
+            # add all active domains
             for dom in running:
                 if dom['domid'] != DOM0_ID:
                     try:
@@ -160,12 +160,14 @@ class XendDomain:
                 dom_name = dom.get('name', 'Domain-%s' % dom_uuid)
                 
                 try:
-                    # instantiate domain if not started.
-                    if not self.domain_lookup_nr(dom_name):
+                    running_dom = self.domain_lookup_nr(dom_name)
+                    if not running_dom:
+                        # instantiate domain if not started.
                         new_dom = XendDomainInfo.createDormant(dom)
                         self._add_domain(new_dom)
-                    # keep track of maanged domains
-                    self._managed_domain_register(new_dom)
+                        self._managed_domain_register(new_dom)
+                    else:
+                        self._managed_domain_register(running_dom)
                 except Exception:
                     log.exception("Failed to create reference to managed "
                                   "domain: %s" % dom_name)
@@ -237,6 +239,9 @@ class XendDomain:
         @raise XendError: fails to save configuration.
         @rtype: None
         """
+        if not self.is_domain_managed(dominfo):
+            return # refuse to save configuration this domain isn't managed
+        
         if dominfo:
             domains_dir = self._managed_path()
             dom_uuid = dominfo.get_uuid()            
index a4afe1d73e5875cbfab040af697090e367c245ec..40fbd1106dc555b7df1d6e37045db79b9700f1a2 100644 (file)
@@ -265,7 +265,7 @@ def createDormant(xeninfo):
     
     log.debug("XendDomainInfo.createDormant(%s)", xeninfo)
     
-    # Remove domid and uuid do not make sense for non-running domains.
+    # domid does not make sense for non-running domains.
     xeninfo.pop('domid', None)
     vm = XendDomainInfo(XendConfig(cfg = xeninfo))
     return vm